1
|
|
|
import * as feathersUtil from 'feathers-commons/lib/utils' |
2
|
|
|
|
3
|
9 |
|
export const each = feathersUtil.each |
4
|
9 |
|
export const some = feathersUtil._.some |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Empty function |
8
|
|
|
*/ |
9
|
|
|
export function noop() { |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Log debug in user's console |
14
|
|
|
* |
15
|
|
|
* @param args |
16
|
|
|
*/ |
17
|
|
|
export function warn(...args) { |
18
|
|
|
/* istanbul ignore next */ |
19
|
|
|
if (console || window.console) { |
20
|
|
|
console.warn('[vue-syncers-feathers]', ...args) |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
9 |
|
const numberRegex = /^\d+$/ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Test if a value seems like a number |
28
|
|
|
* |
29
|
|
|
* @param value |
30
|
|
|
* @returns {boolean} |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
export function isNumericIDLike(value) { |
34
|
22 |
|
return (typeof value !== 'number' && numberRegex.test(value)) |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Return object with only selected keys |
39
|
|
|
* |
40
|
|
|
* @from https://github.com/feathersjs/feathers-memory |
41
|
|
|
* @param source |
42
|
|
|
* @param keys |
43
|
|
|
* @returns {object} |
44
|
|
|
*/ |
45
|
|
|
export function pick(source, ...keys) { |
46
|
3 |
|
const result = {} |
47
|
3 |
|
for (const key of keys) { |
48
|
6 |
|
result[key] = source[key] |
49
|
|
|
} |
50
|
3 |
|
return result |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Check if object is JSONable |
55
|
|
|
* |
56
|
|
|
* @from https://github.com/vuejs/vue/blob/0b902e0c28f4f324ffb8efbc9db74127430f8a42/src/shared/util.js#L155 |
57
|
|
|
* @param {*} obj |
58
|
|
|
* @returns {boolean} |
59
|
|
|
*/ |
60
|
|
|
function isObject(obj) { |
61
|
24 |
|
return obj !== null && typeof obj === 'object' |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Loosely check if objects are equal |
66
|
|
|
* |
67
|
|
|
* @from https://github.com/vuejs/vue/blob/0b902e0c28f4f324ffb8efbc9db74127430f8a42/src/shared/util.js |
68
|
|
|
* @param {*} a |
69
|
|
|
* @param {*} b |
70
|
|
|
* @returns {boolean} |
71
|
|
|
*/ |
72
|
|
|
export function looseEqual(a, b) { |
73
|
12 |
|
const isObjectA = isObject(a) |
74
|
12 |
|
const isObjectB = isObject(b) |
75
|
12 |
|
if (isObjectA && isObjectB) { |
76
|
1 |
|
try { |
77
|
1 |
|
return JSON.stringify(a) === JSON.stringify(b) |
78
|
|
|
} catch (err) { |
79
|
|
|
// Possible circular reference |
80
|
|
|
return a === b |
81
|
|
|
} |
82
|
11 |
|
} else if (!isObjectA && !isObjectB) { |
83
|
|
|
return String(a) === String(b) |
84
|
|
|
} else { |
85
|
11 |
|
return false |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|